﻿namespace RL
{
    using System;

    public class StatusBar
    {
        internal static string FadeoutStatus = ("\r\nfunction FadeoutStatus()\r\n{\r\n" + JQuery.FadeOut(JQuery.SelectId("AjaxPlaceHolderStatusBar"), speed.slow, true) + "\r\n}\r\n");
        internal static string HideStatus = ("\r\nfunction HideStatus()\r\n{\r\n" + JQuery.RemoveClass(JQuery.SelectId("AjaxPlaceHolderStatusBar"), true) + JQuery.Hide(JQuery.SelectId("AjaxPlaceHolderStatusBar"), true) + "\r\n}\r\n");
        internal static readonly string Initialization = " \r\n     if (typeof AjaxPlaceHolderStatusBar == 'undefined')\r\n    {\r\n        AjaxPlaceHolderStatusBar =\r\n            $(\"<div id='AjaxPlaceHolderStatusBar' class='status_hidden ajax_manager_statusbar'></div>\")\r\n                    .appendTo(document.body)\r\n                    ;\r\n    }\r\n";
        internal static string SetFadeTimeout = "\r\nvar StatusBarFadeTimer;\r\nfunction SetFadeTimeout(time)\r\n{ \r\nclearTimeout(StatusBarFadeTimer);\r\nStatusBarFadeTimer = setTimeout('FadeoutStatus()',time); \r\n}";
        internal static string SetHideTimeout = "\r\nvar StatusBarHideTimer;\r\nfunction SetHideTimeout (time)\r\n{ \r\nclearTimeout(StatusBarHideTimer);\r\nStatusBarHideTimer = setTimeout('HideAjaxStatus()',time);\r\n}";
        internal static string showStatusMessage = "\r\n\r\nfunction showStatusMessage(pos,message,width,height,background_color,color,corner_distance,border_color,set_timeout,timeout_time,speed)\r\n{\r\n$('#AjaxPlaceHolderStatusBar').css('color', color);\r\n$('#AjaxPlaceHolderStatusBar').css('background-color', background_color);\r\n\r\n\r\nswitch(pos)\r\n{\r\ncase 'top':\r\n$('#AjaxPlaceHolderStatusBar').css('height', height);\r\n$('#AjaxPlaceHolderStatusBar').css('left', '0px');\r\n$('#AjaxPlaceHolderStatusBar').css('right', '0px');\r\n$('#AjaxPlaceHolderStatusBar').css('top', corner_distance);\r\nbreak;\r\n\r\ncase 'bottom':\r\n$('#AjaxPlaceHolderStatusBar').css('height', height);\r\n$('#AjaxPlaceHolderStatusBar').css('left', '0px');\r\n$('#AjaxPlaceHolderStatusBar').css('right', '0px');\r\n$('#AjaxPlaceHolderStatusBar').css('bottom', corner_distance);\r\nbreak;\r\n\r\ncase 'left':\r\n$('#AjaxPlaceHolderStatusBar').css('width', width);\r\n$('#AjaxPlaceHolderStatusBar').css('left', corner_distance);\r\n$('#AjaxPlaceHolderStatusBar').css('top', '0px');\r\n$('#AjaxPlaceHolderStatusBar').css('bottom', '0px');\r\nbreak;\r\n\r\ncase 'right':\r\n$('#AjaxPlaceHolderStatusBar').css('width', width);\r\n$('#AjaxPlaceHolderStatusBar').css('right', corner_distance);\r\n$('#AjaxPlaceHolderStatusBar').css('top', '0px');\r\n$('#AjaxPlaceHolderStatusBar').css('bottom', '0px');\r\nbreak;\r\ncase 'topright':\r\n$('#AjaxPlaceHolderStatusBar').css('height', height);\r\n$('#AjaxPlaceHolderStatusBar').css('width', width);\r\n$('#AjaxPlaceHolderStatusBar').css('right', corner_distance);\r\n$('#AjaxPlaceHolderStatusBar').css('top', corner_distance);\r\nbreak;\r\ncase 'bottomright':\r\n$('#AjaxPlaceHolderStatusBar').css('height', height);\r\n$('#AjaxPlaceHolderStatusBar').css('width', width);\r\n$('#AjaxPlaceHolderStatusBar').css('right', corner_distance);\r\n$('#AjaxPlaceHolderStatusBar').css('bottom', corner_distance);\r\nbreak;\r\ncase 'topleft':\r\n$('#AjaxPlaceHolderStatusBar').css('height', height);\r\n$('#AjaxPlaceHolderStatusBar').css('width', width);\r\n$('#AjaxPlaceHolderStatusBar').css('left', corner_distance);\r\n$('#AjaxPlaceHolderStatusBar').css('top', corner_distance);\r\nbreak;\r\ncase 'bottomleft':\r\n$('#AjaxPlaceHolderStatusBar').css('height', height);\r\n$('#AjaxPlaceHolderStatusBar').css('width', width);\r\n$('#AjaxPlaceHolderStatusBar').css('left', corner_distance);\r\n$('#AjaxPlaceHolderStatusBar').css('bottom', corner_distance);\r\nbreak;\r\n}\r\n\r\n$('#AjaxPlaceHolderStatusBar').css('border-style', 'solid');\r\n$('#AjaxPlaceHolderStatusBar').css('border-width', '1px');\r\n$('#AjaxPlaceHolderStatusBar').css('border-color', border_color);\r\n\r\n\r\n$('#AjaxPlaceHolderStatusBar').html(message);\r\n$('#AjaxPlaceHolderStatusBar').show(speed);\r\n\r\nvar timeoutLower = set_timeout.toLowerCase();\r\nif(timeoutLower == 'true')\r\n{\r\n    SetFadeTimeout(timeout_time);\r\n}\r\n    \r\n}\r\n\r\n";

        public static string fadeOutStatus(bool terminate)
        {
            return (" FadeoutStatus()" + utility.terminater(terminate));
        }

        public static string hideStatus(bool terminate)
        {
            return (" HideStatus()" + utility.terminater(terminate));
        }

        public static string setFadeTimeout(int time)
        {
            return (" SetFadeTimeout(" + time.ToString() + "); ");
        }

        public static string setHideTimeout(int time)
        {
            return (" SetHideTimeout(" + time.ToString() + "); ");
        }

        public static string ShowStatusMessage(Position position, string message, string width, string height, string background_color, string color, string top_distance, string border_color, bool set_timeout, int timeout_length, speed Speed)
        {
            return string.Format("showStatusMessage('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}');", new object[] { position.ToString(), message, width, height, background_color, color, top_distance, border_color, set_timeout.ToString(), timeout_length.ToString(), Speed.ToString() });
        }

        public enum Position
        {
            right,
            top,
            bottom,
            left,
            topright,
            bottomright,
            topleft,
            bottomleft
        }
    }
}

